/***************************************************************************
 *   Copyright (C) 2007 by Alexandre Masselot,,,   *
 *   alex@alex-laptop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef BOLPEAKLCMS_H
#define BOLPEAKLCMS_H

#include <math.h>
#include <float.h>

#if defined(_MSC_VER) && !defined(isnan)
#define isnan(f) _isnan(f)
#endif

#ifdef HAVE_BOOST_SERIALIZATION
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/base_object.hpp>
#endif

#ifdef HAVE_PROTOBUF
#ifdef _MSC_VER
// we don't create DLLs and thus don't need to pay attention to this warning
#pragma warning( disable: 4251 )
#endif
#include "runlcmsms.pb.h"
#endif

#include "peakintensity.h"

namespace bol {

/**
  @author Alexandre Masselot,,, <alex@alex-laptop>
 */
  class PeakLcms : public PeakIntensity
  {
    private:
      double m_retentionTime;

#ifdef HAVE_BOOST_SERIALIZATION
      // *** BOOST serialisation code ***
      friend class boost::serialization::access; // gives access to serialisator
      template<class Archive> void serialize ( Archive & ar, const unsigned int version ) const
      {
        // base class serialisation - warning, as there are several variable, the order is critical...
        // ... well not for XML. But for most other archive types.
        ar & boost::serialization::make_nvp("PeakIntensity", boost::serialization::base_object<PeakIntensity> ( *this ));

        ar & boost::serialization::make_nvp("retentionTime", m_retentionTime);
      }
#endif

    public:
#ifdef _MSC_VER
#ifndef NAN // Miscrosot Visual C lacks a NAN definition in math
      static const double NAN;
#endif
#endif

      PeakLcms(const double m, const Pchargemask charges, const double i=0):PeakIntensity(m, charges, i){
        m_retentionTime=NAN;
      }
      ~PeakLcms(){}

      void setRetentionTime(double theValue) {
        m_retentionTime = theValue;
      }


      double retentionTime() const {
        return m_retentionTime;
      }
      friend ostream& operator<<(ostream& out, const PeakLcms& p);
      friend ostream& operator<<(ostream& out, const PeakLcms* p);

  };

#ifdef HAVE_PROTOBUF
  static inline bool operator<< (protobuf::RunLcmsms::Spectrum::Peak& pb, const class PeakLcms& p) {
//    pb.set_retentiontime(p.retentionTime()); // stored in spectrum instead
    (pb) << (static_cast< class PeakIntensity > (p));
    return true;
  }

  static inline bool operator>> (const protobuf::RunLcmsms::Spectrum::Peak& pb, class PeakLcms& p) {
//    p.setRetentionTime(pb.retentiontime()); // stored in spectrum instead
    (pb) >> (static_cast< class PeakIntensity& > (p));
    return true;
  }

#endif
  
}

#ifdef HAVE_BOOST_SERIALIZATION
#if defined(WIN32) && (BOOST_VERSION < 103600)
// other wise Visual Studio spits error messages
#include <boost/serialization/extended_type_info_typeid.hpp>
#endif
BOOST_CLASS_EXPORT_GUID(bol::PeakLcms , "PeakLcms") // register GUID
#endif
    
#endif
